#ifndef THINK_THINK_RESPONSE_H
#define THINK_THINK_RESPONSE_H

static char* think_response =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | ThinkPHP [ WE CAN DO IT JUST THINK ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: liu21st <liu21st@gmail.com>\n"
	"// +----------------------------------------------------------------------\n"
	"\n"
	"namespace think;\n"
	"\n"
	"use think\\response\\Json as JsonResponse;\n"
	"use think\\response\\Jsonp as JsonpResponse;\n"
	"use think\\response\\Redirect as RedirectResponse;\n"
	"use think\\response\\View as ViewResponse;\n"
	"use think\\response\\Xml as XmlResponse;\n"
	"\n"
	"class Response\n"
	"{\n"
	"    // 原始数据\n"
	"    protected $data;\n"
	"\n"
	"    // 当前的contentType\n"
	"    protected $contentType = \'text/html\';\n"
	"\n"
	"    // 字符集\n"
	"    protected $charset = \'utf-8\';\n"
	"\n"
	"    //状态\n"
	"    protected $code = 200;\n"
	"\n"
	"    // 输出参数\n"
	"    protected $options = [];\n"
	"    // header参数\n"
	"    protected $header = [];\n"
	"\n"
	"    protected $content = null;\n"
	"\n"
	"    /**\n"
	"     * 构造函数\n"
	"     * @access   public\n"
	"     * @param mixed $data    输出数据\n"
	"     * @param int   $code\n"
	"     * @param array $header\n"
	"     * @param array $options 输出参数\n"
	"     */\n"
	"    public function __construct($data = \'\', $code = 200, array $header = [], $options = [])\n"
	"    {\n"
	"        $this->data($data);\n"
	"        if (!empty($options)) {\n"
	"            $this->options = array_merge($this->options, $options);\n"
	"        }\n"
	"        $this->contentType($this->contentType, $this->charset);\n"
	"        $this->header = array_merge($this->header, $header);\n"
	"        $this->code   = $code;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 创建Response对象\n"
	"     * @access public\n"
	"     * @param mixed  $data    输出数据\n"
	"     * @param string $type    输出类型\n"
	"     * @param int    $code\n"
	"     * @param array  $header\n"
	"     * @param array  $options 输出参数\n"
	"     * @return Response|JsonResponse|ViewResponse|XmlResponse|RedirectResponse|JsonpResponse\n"
	"     */\n"
	"    public static function create($data = \'\', $type = \'\', $code = 200, array $header = [], $options = [])\n"
	"    {\n"
	"        $class = false !== strpos($type, \'\\\\\') ? $type : \'\\\\think\\\\response\\\\\' . ucfirst(strtolower($type));\n"
	"        if (class_exists($class)) {\n"
	"            $response = new $class($data, $code, $header, $options);\n"
	"        } else {\n"
	"            $response = new static($data, $code, $header, $options);\n"
	"        }\n"
	"\n"
	"        return $response;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 发送数据到客户端\n"
	"     * @access public\n"
	"     * @return mixed\n"
	"     * @throws \\InvalidArgumentException\n"
	"     */\n"
	"    public function send()\n"
	"    {\n"
	"        // 监听response_send\n"
	"        Hook::listen(\'response_send\', $this);\n"
	"\n"
	"        // 处理输出数据\n"
	"        $data = $this->getContent();\n"
	"\n"
	"        // Trace调试注入\n"
	"        if (Env::get(\'app_trace\', Config::get(\'app_trace\'))) {\n"
	"            Debug::inject($this, $data);\n"
	"        }\n"
	"\n"
	"        if (200 == $this->code) {\n"
	"            $cache = Request::instance()->getCache();\n"
	"            if ($cache) {\n"
	"                $this->header[\'Cache-Control\'] = \'max-age=\' . $cache[1] . \',must-revalidate\';\n"
	"                $this->header[\'Last-Modified\'] = gmdate(\'D, d M Y H:i:s\') . \' GMT\';\n"
	"                $this->header[\'Expires\']       = gmdate(\'D, d M Y H:i:s\', $_SERVER[\'REQUEST_TIME\'] + $cache[1]) . \' GMT\';\n"
	"                Cache::tag($cache[2])->set($cache[0], [$data, $this->header], $cache[1]);\n"
	"            }\n"
	"        }\n"
	"\n"
	"        if (!headers_sent() && !empty($this->header)) {\n"
	"            // 发送状态码\n"
	"            http_response_code($this->code);\n"
	"            // 发送头部信息\n"
	"            foreach ($this->header as $name => $val) {\n"
	"                if (is_null($val)) {\n"
	"                    header($name);\n"
	"                } else {\n"
	"                    header($name . \':\' . $val);\n"
	"                }\n"
	"            }\n"
	"        }\n"
	"\n"
	"        echo $data;\n"
	"\n"
	"        if (function_exists(\'fastcgi_finish_request\')) {\n"
	"            // 提高页面响应\n"
	"            fastcgi_finish_request();\n"
	"        }\n"
	"\n"
	"        // 监听response_end\n"
	"        Hook::listen(\'response_end\', $this);\n"
	"\n"
	"        // 清空当次请求有效的数据\n"
	"        if (!($this instanceof RedirectResponse)) {\n"
	"            Session::flush();\n"
	"        }\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 处理数据\n"
	"     * @access protected\n"
	"     * @param mixed $data 要处理的数据\n"
	"     * @return mixed\n"
	"     */\n"
	"    protected function output($data)\n"
	"    {\n"
	"        return $data;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 输出的参数\n"
	"     * @access public\n"
	"     * @param mixed $options 输出参数\n"
	"     * @return $this\n"
	"     */\n"
	"    public function options($options = [])\n"
	"    {\n"
	"        $this->options = array_merge($this->options, $options);\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 输出数据设置\n"
	"     * @access public\n"
	"     * @param mixed $data 输出数据\n"
	"     * @return $this\n"
	"     */\n"
	"    public function data($data)\n"
	"    {\n"
	"        $this->data = $data;\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 设置响应头\n"
	"     * @access public\n"
	"     * @param string|array $name  参数名\n"
	"     * @param string       $value 参数值\n"
	"     * @return $this\n"
	"     */\n"
	"    public function header($name, $value = null)\n"
	"    {\n"
	"        if (is_array($name)) {\n"
	"            $this->header = array_merge($this->header, $name);\n"
	"        } else {\n"
	"            $this->header[$name] = $value;\n"
	"        }\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 设置页面输出内容\n"
	"     * @param $content\n"
	"     * @return $this\n"
	"     */\n"
	"    public function content($content)\n"
	"    {\n"
	"        if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([\n"
	"            $content,\n"
	"            \'__toString\',\n"
	"        ])\n"
	"        ) {\n"
	"            throw new \\InvalidArgumentException(sprintf(\'variable type error： %s\', gettype($content)));\n"
	"        }\n"
	"\n"
	"        $this->content = (string) $content;\n"
	"\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 发送HTTP状态\n"
	"     * @param integer $code 状态码\n"
	"     * @return $this\n"
	"     */\n"
	"    public function code($code)\n"
	"    {\n"
	"        $this->code = $code;\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * LastModified\n"
	"     * @param string $time\n"
	"     * @return $this\n"
	"     */\n"
	"    public function lastModified($time)\n"
	"    {\n"
	"        $this->header[\'Last-Modified\'] = $time;\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * Expires\n"
	"     * @param string $time\n"
	"     * @return $this\n"
	"     */\n"
	"    public function expires($time)\n"
	"    {\n"
	"        $this->header[\'Expires\'] = $time;\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * ETag\n"
	"     * @param string $eTag\n"
	"     * @return $this\n"
	"     */\n"
	"    public function eTag($eTag)\n"
	"    {\n"
	"        $this->header[\'ETag\'] = $eTag;\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 页面缓存控制\n"
	"     * @param string $cache 状态码\n"
	"     * @return $this\n"
	"     */\n"
	"    public function cacheControl($cache)\n"
	"    {\n"
	"        $this->header[\'Cache-control\'] = $cache;\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 页面输出类型\n"
	"     * @param string $contentType 输出类型\n"
	"     * @param string $charset     输出编码\n"
	"     * @return $this\n"
	"     */\n"
	"    public function contentType($contentType, $charset = \'utf-8\')\n"
	"    {\n"
	"        $this->header[\'Content-Type\'] = $contentType . \'; charset=\' . $charset;\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 获取头部信息\n"
	"     * @param string $name 头部名称\n"
	"     * @return mixed\n"
	"     */\n"
	"    public function getHeader($name = \'\')\n"
	"    {\n"
	"        if (!empty($name)) {\n"
	"            return isset($this->header[$name]) ? $this->header[$name] : null;\n"
	"        } else {\n"
	"            return $this->header;\n"
	"        }\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 获取原始数据\n"
	"     * @return mixed\n"
	"     */\n"
	"    public function getData()\n"
	"    {\n"
	"        return $this->data;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 获取输出数据\n"
	"     * @return mixed\n"
	"     */\n"
	"    public function getContent()\n"
	"    {\n"
	"        if (null == $this->content) {\n"
	"            $content = $this->output($this->data);\n"
	"\n"
	"            if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([\n"
	"                $content,\n"
	"                \'__toString\',\n"
	"            ])\n"
	"            ) {\n"
	"                throw new \\InvalidArgumentException(sprintf(\'variable type error： %s\', gettype($content)));\n"
	"            }\n"
	"\n"
	"            $this->content = (string) $content;\n"
	"        }\n"
	"        return $this->content;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 获取状态码\n"
	"     * @return integer\n"
	"     */\n"
	"    public function getCode()\n"
	"    {\n"
	"        return $this->code;\n"
	"    }\n"
	"}\n"
	"\n"
;
#endif